package bookStore.dao.privilege;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.handlers.ColumnListHandler;

import bookStore.dao.DaoTemplate;
import bookStore.po.Resource;

public class ResourceDaoImpl extends DaoTemplate implements ResourceDao {

	public ResourceDaoImpl(Connection connection) {
		super(connection);

	}

	@Override
	public List<String> getBlackListForUser(int userId) {
		if (userId != -1) {
			this.sql = "select resource.url " + "from resource " + "where resource.id in("
					+ "  select role_resouce.resourceId " + "  from role_resouce "
					+ "  where role_resouce.roleId not in( " + "    select user_roles.roleId " + "    from user_roles "
					+ "    where userId=? " + "  ) " + ")";
			try {
				return this.queryRunner.query(connection, sql, new ColumnListHandler<String>(1), userId);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} else {
				this.sql="select url from resource";
				try {
					return this.queryRunner.query(connection, sql, new ColumnListHandler<String>(1));
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}

		return null;
	}

	@Override
	public List<Resource> queryAll(int offset, int pageSize) {
		return null;
	}

	@Override
	public void save(Resource t) {
	}

	@Override
	public Resource get(int id) {
		return null;
	}

	@Override
	public long count() {
		return 0;
	}

	@Override
	public void update(Resource t) {
	}

	@Override
	public void delete(int id) {
	}

}
